<?php

/**
 * User
 * 
 * 
 *
 * @category   Model
 * @package    User
 * @subpackage AppModel
 * @copyright  Copyright (c) 2012 Victor Rosset
 * @license    
 * @version    0.1 alpha
 * @link       http://www.tucho235.com.ar
 * @since      25-ago-2012
 * @author     Victor Rosset <victorrosset@gmail.com> @tucho235
 * @php        5.3.13
 * 
 */

App::uses('AuthComponent', 'Controller/Component');
 
class User extends AppModel
{
    public $name = 'User';
    
    public $validate = array(
        'username' => array(
            'required' => array(
                'rule'    => array('notEmpty'),
                'message' => 'Campo requerido'
            )
        ),
        'password' => array(
            'required' => array(
                'rule'    => array('notEmpty'),
                'message' => 'Campo requerido'
            )
        ),
        'role' => array(
            'valid' => array(
                'rule' => array('inList', array('admin', 'author')),
                'message'    => 'Campo requerido',
                'allowEmpty' => false
            )
        )
    );

    public function beforeSave($options = array()) {
        if (isset($this->data[$this->alias]['password'])) {
            $this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']);
        }
        return true;
    }

}